package com.example.myhl7project;

import ca.uhn.hl7v2.DefaultHapiContext;
import ca.uhn.hl7v2.HapiContext;
import ca.uhn.hl7v2.parser.Parser;
import ca.uhn.hl7v2.parser.ParserConfiguration;
import ca.uhn.hl7v2.parser.PipeParser;
import ca.uhn.hl7v2.validation.impl.ValidationContextFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class HL7Config {

    @Bean
    public HapiContext hapiContext() {
        HapiContext context = new DefaultHapiContext();
        ParserConfiguration parserConfig = context.getParserConfiguration();
        parserConfig.setAllowUnknownVersions(true);
        parserConfig.setValidating(false); // 禁用验证
        return context;
    }

    @Bean
    public Parser hl7Parser(HapiContext hapiContext) {
        PipeParser parser = new PipeParser(hapiContext);
        parser.setValidationContext(hapiContext.getValidationContext());
        return parser;
    }
}